#include <iostream>

using namespace std;

const int max_n = 1000000 + 10;
int p[max_n];

int find(int x) {
    if (p[x] == x) return x;
    return p[x] = find(p[x]);
}

void merge(int x, int y) {
    int fx = find(x);
    int fy = find(y);
    p[fx] = fy;
    return ;
}

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
        p[i] = i;
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        merge(a, b);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (p[i] == i) ans++;
    }
    printf("%d\n", ans);
    return 0;
}